package com.itjob.deep.servlet;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.itjob.deep.util.CookieUtil;

public class QuitServlet extends HttpServlet {
	
	private static final long serialVersionUID = -38185498074493266L;

	@Override
	protected void service(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		Cookie userCookie = CookieUtil.getCookie(request.getCookies(), "user");
		
		if (userCookie != null) {
			
			Cookie cookie = new Cookie("user", null);
			cookie.setMaxAge(0);
			
			response.addCookie(cookie);
			
		}
		
		request.getSession().invalidate();
		request.getRequestDispatcher("/login.jsp").forward(request, response);
	}
}
